<?php if(!class_exists("View", false)) exit("no direct access allowed");?><main id="main" class="in">
    <style>
        .main-header>h2 {
            display: block;
            float: left;
            margin: 0 10px 0 0;
            font-size: 14px;
            line-height: 34px;
        }
        .main-header>h2 .label-id {
            margin-right: 5px;
        }
        .label-id {
            display: inline-block;
            min-width: 30px;
            padding: 0 5px;
            font-size: 12px;
            line-height: 16px;
            color: #838a9d;
            text-align: center;
            vertical-align: middle;
            background-color: transparent;
            border: 1px solid #838a9d;
            border-radius: 2px;
        }
        strong {
            font-weight: 700;
            font-size: 14px;
            color: black;
        }
        .text-muted{
            font-size: 12px;
        }
    </style>
    <div class="container-fluid">
        <div class="panel">
            <div class="panel-heading">
                <h2>
                    <span class="label label-id"><?php echo htmlspecialchars($user['id'], ENT_QUOTES, "UTF-8"); ?></span>
                    <strong><a href="/www/index.php?m=user&amp;f=view&amp;account=admin"><?php echo htmlspecialchars($user['realname'], ENT_QUOTES, "UTF-8"); ?></a>
                    </strong>
                    <small>&nbsp;<i class="icon-angle-right"></i>&nbsp;编辑用户</small>
                </h2>
            </div>
            <div class="panel-body">
                <div class="panel-group" id="accordionPanels" aria-multiselectable="true">
                    <div class="panel panel-default">
                      <div class="panel-heading" id="headingOne">
                        <h4 class="panel-title">
                          <a data-toggle="collapse" class="collapsed text-muted" data-parent="#accordionPanels" href="#collapseOne">
                            基本信息
                          </a>
                        </h4>
                      </div>
                      <div id="collapseOne" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <form class="form-horizontal form-condensed">
                                <div class="form-group">
                                  <label for="realname" class="col-sm-2">真实姓名</label>
                                  <div class="col-md-6 col-sm-10">
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($user['realname'], ENT_QUOTES, "UTF-8"); ?>" id="realname" name="realname" placeholder="真实姓名">
                                    <input type="hidden" class="form-control" value="<?php echo htmlspecialchars($user['id'], ENT_QUOTES, "UTF-8"); ?>" id="id" name="id">
                                  </div>
                                </div>
                                <div class="form-group">
                                  <label for="dept" class="col-sm-2">所属部门</label>
                                  <div class="col-md-6 col-sm-10">
                                    <select class="form-control" id="dept">
                                        <option value="">请选择部门</option>
                                        <?php if(!empty($depts)){ $_foreach_de_counter = 0; $_foreach_de_total = count($depts);?><?php foreach( $depts as $k => $de ) : ?><?php $_foreach_de_index = $_foreach_de_counter;$_foreach_de_iteration = $_foreach_de_counter + 1;$_foreach_de_first = ($_foreach_de_counter == 0);$_foreach_de_last = ($_foreach_de_counter == $_foreach_de_total - 1);$_foreach_de_counter++;?>
                                        <?php if ($user['dept'] == $de['id']) : ?>
                                        <option selected="selected" value="<?php echo htmlspecialchars($de['id'], ENT_QUOTES, "UTF-8"); ?>">/<?php echo htmlspecialchars($de['name'], ENT_QUOTES, "UTF-8"); ?></option>
                                        <?php else : ?>
                                        <option value="<?php echo htmlspecialchars($de['id'], ENT_QUOTES, "UTF-8"); ?>">/<?php echo htmlspecialchars($de['name'], ENT_QUOTES, "UTF-8"); ?></option>
                                        <?php endif; ?>
                                        <?php if(!empty($de['children'])){ $_foreach_dec_counter = 0; $_foreach_dec_total = count($de['children']);?><?php foreach( $de['children'] as $k => $dec ) : ?><?php $_foreach_dec_index = $_foreach_dec_counter;$_foreach_dec_iteration = $_foreach_dec_counter + 1;$_foreach_dec_first = ($_foreach_dec_counter == 0);$_foreach_dec_last = ($_foreach_dec_counter == $_foreach_dec_total - 1);$_foreach_dec_counter++;?>
                                        <?php if ($user['dept'] == $dec['id']) : ?>
                                        <option selected="selected" value="<?php echo htmlspecialchars($dec['id'], ENT_QUOTES, "UTF-8"); ?>">/<?php echo htmlspecialchars($de['name'], ENT_QUOTES, "UTF-8"); ?>/<?php echo htmlspecialchars($dec['name'], ENT_QUOTES, "UTF-8"); ?></option>
                                        <?php else : ?>
                                        <option value="<?php echo htmlspecialchars($dec['id'], ENT_QUOTES, "UTF-8"); ?>">/<?php echo htmlspecialchars($de['name'], ENT_QUOTES, "UTF-8"); ?>/<?php echo htmlspecialchars($dec['name'], ENT_QUOTES, "UTF-8"); ?></option>
                                        <?php endif; ?>
                                        <?php endforeach; }?>
                                        
                                        <?php endforeach; }?>
                                    </select>
                                  </div>
                                </div>
                                <div class="form-group">
                                  <label for="group" class="col-sm-2">权限</label>
                                  <div class="col-sm-6">
                                    <?php if(!empty($groups)){ $_foreach_v_counter = 0; $_foreach_v_total = count($groups);?><?php foreach( $groups as $k => $v ) : ?><?php $_foreach_v_index = $_foreach_v_counter;$_foreach_v_iteration = $_foreach_v_counter + 1;$_foreach_v_first = ($_foreach_v_counter == 0);$_foreach_v_last = ($_foreach_v_counter == $_foreach_v_total - 1);$_foreach_v_counter++;?>
                                    <label class="checkbox-inline">
                                      
                                      <input type="checkbox" name="permission" <?php if (in_array($v['role'],explode(",",$user['role']))) : ?>checked="checked"<?php endif; ?> value="<?php echo htmlspecialchars($v['role'], ENT_QUOTES, "UTF-8"); ?>"> <?php echo htmlspecialchars($v['name'], ENT_QUOTES, "UTF-8"); ?>
                                    </label>
                                    <?php endforeach; }?>
                                  </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button class="btn btn-primary btn-lg btn-save" type="button">保存</button>
                                        <button class="btn btn-lg" onclick="history.go(-1)" type="button">返回</button>
                                    </div>
                                </div>                                
                              </form>
                        </div>
                      </div>
                    </div>                    
                </div>
            </div>
        </div>
    </div>
</main>
<script src="http://p1.renbenzhihui.com/zui/js/all.js"></script>
<script src="/i/js/util.js"></script>
<script>
  $(function(){
    $('.btn-save').click(function(){
      var realname = Utils.paseData($('#realname').val());
      var dept = Utils.paseData($('#dept').val());
      var pers = '';
      $('input[name="permission"]').each(function() { 
        //alert($(this).attr('checked'))
        if ($(this).attr('checked') == 'checked') { 
          pers+=$(this).val()+',';
        } 
      });
      pers = pers.substring(0,pers.length-1);
      var id = Utils.paseData($('#id').val());
      if(realname != '' && dept != '' && pers != '' && id != ''){
        $.post('<?php echo url(array('c'=>"System", 'a'=>"UpdateUser", ));?>',{uid:id,dept:dept,pers:pers,realname:realname},function(data){
                data = JSON.parse(data);
                if(data.code/1 == 1){
                  location.href='<?php echo url(array('c'=>"System", 'a'=>"Index", ));?>';
                }else{
                  new $.zui.Messager(data.msg, {
                      type: 'danger',
                      icon: 'exclamation-sign',
                      placement: 'center' // 定义显示位置
                  }).show();
                }
        });
      }else{
        new $.zui.Messager('必要字段不能为空。', {
            icon: 'bell' // 定义消息图标
        }).show();
      }
    });
  });
</script>